package com.crm.service.impl.customerManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.customMapper.customerManagerCustomMapper.CustomerPayCustomMapper;
import com.crm.dao.mapper.customerManager.CustomerPayMapper;
import com.crm.model.entity.customerManager.CustomerPay;
import com.crm.model.entity.customerManager.CustomerPayExample;
import com.crm.model.entity.customerManager.CustomerPoolCompany;
import com.crm.model.entity.customerManager.CustomerPoolCompanyExample;
import com.crm.model.qo.customerManager.CustomerPayQO;
import com.crm.model.vo.customerManager.CustomerPayAllInfoVO;
import com.crm.model.vo.customerManager.CustomerPayDetailVO;
import com.crm.model.vo.customerManager.CustomerPayVO;
import com.crm.service.customerManager.CustomerPayDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author:chaifuyou
 * @Date: 2021/4/30 9:48
 */
@Service
public class CustomerPayDbServiceImpl implements CustomerPayDbService {

    @Autowired //自动生成
    private CustomerPayMapper customerPayMapper;

    @Autowired
    private CustomerPayCustomMapper customerPayCustomMapper;

    /**
     * 客户充值列表
     * @param dateUnit
     * @param order
     * @return
     */
    @Override
    public List<CustomerPayVO> selectCustomerPayList(Integer dateUnit, StringBuilder order, CustomerPayQO qo) {
        return customerPayCustomMapper.selectCustomerPayList(dateUnit,order,qo);
    }

    /**
     * 添加客户充值信息
     * @param customerPay
     */
    @Override
    public Integer saveCustomerPay(CustomerPay customerPay) {
        return customerPayMapper.insertSelective(customerPay);
    }

    /**
     * 通过id查询客户充值信息
     * @param chsCustomerPayId
     * @return
     */
    @Override
    public CustomerPay selectCustomerPayById(String chsCustomerPayId) {
        return customerPayCustomMapper.selectCustomerPayById(chsCustomerPayId);
    }

    /**
     * 修改充值信息
     * @param cpay
     * @return
     */
    @Override
    public Integer updateCustomerPay(CustomerPay cpay) {
        return customerPayMapper.updateByPrimaryKeySelective(cpay);
    }

    /**
     * 财务确认收款
     * @param
     */
    @Override
    public boolean notarizeCustomerPay(CustomerPay customerPay) {
        return customerPayMapper.updateByPrimaryKeySelective(customerPay) > 0;
    }

    @Override
    public CustomerPayDetailVO queryCustomerPayDetail(String customerPayId) {
        return customerPayCustomMapper.queryCustomerPayDetail(customerPayId);
    }

    @Override
    public BigDecimal selectPayMoneyCount(String customerPayId,Integer dateUnit) {
        return customerPayCustomMapper.selectPayMoneyCount(customerPayId,dateUnit);
    }

    /**
     * 通过客户id和充值金额查询
     * @param customerId
     * @param customerPay
     * @return
     */
    @Override
    public List<CustomerPay> selectCustomerId(String customerId, BigDecimal customerPay) {
        CustomerPayExample payExample = new CustomerPayExample();
        CustomerPayExample.Criteria criteria = payExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andPayMoneyEqualTo(customerPay);
        criteria.andDeleteStatusEqualTo(0);
        List<CustomerPay> list = customerPayMapper.selectByExample(payExample);
        return list;
    }

    @Override
    public CustomerPay selectByPrimaryKey(String chsCustomerPayId) {
        return customerPayMapper.selectByPrimaryKey(chsCustomerPayId);
    }

    @Override
    public int updatePayInfo(CustomerPay cp) {
        return customerPayCustomMapper.updatePayInfo(cp);
    }

    @Override
    public CustomerPayAllInfoVO queryDetail(String customerPayId) {
        return customerPayCustomMapper.queryDetail(customerPayId);
    }
}
